
/**
 * @desc:  是否应用到设备弹窗
 * @author qiankui
 * @date 2023-6-15 17:01:23
*/
<template>
    <el-dialog append-to-body :visible="deleteFlag" class="khzhgl-xq-dialog" width="600px" :title="$t('Operate Confirm')" :before-close="handleCloseDialog">
        <h3 style="text-align: center"> <i class="el-icon-warning" style="color: #ff8d1a;font-size: 50px;vertical-align: middle"></i>
            <!--是否应用于设备？-->
            {{this.i18n.t('Is it applied to the device')}}
        </h3>
        <br>
        <el-form label-width="120px" :model="form">
            <el-form-item :label="$t('Device name')">
                <el-select v-model="form.deviceCodes"
                           multiple
                           collapse-tags
                           placeholder="">
                    <el-option :label="item.deviceName" :value="item.deviceCode"
                               v-for="(item,index) in devOptions"
                               :key="item.deviceCode"></el-option>
                </el-select>
            </el-form-item>
            <!--组织下的人员-->
            <el-form-item :label="$t('Personnel under the organization')" v-if="applyType==3">
                <el-select v-model="form.isDelPersion" placeholder="">
                    <!--保留（转移到默认组织内）-->
                    <el-option :label="$t('Reserved (transferred to default organization)')" value="0"></el-option>
                    <!--删除-->
                    <el-option :label="$t('delete')" value="1"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div class="footBtnBox">
            <el-button size="mini" type="handle" @click="handleCloseDialog">{{this.i18n.t('Cancel')}}</el-button>
            <el-button size="mini" type="primary" :loading="saveLoading" @click="save">{{this.i18n.t('OK')}}</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import {deviceinfoGetallonlinedevices} from "@/api/pcmj/sbsj";
    import {
        personnelinfoBatchdelete,
        personnelinfoCleanallperson
    } from "@/api/pcmj/zzxx";
export default {
    name: "detail",
    components: {},
    props: {
        applyType:{
            type:Number,
            default:0
        },
        isDelPersion:{
            type: Boolean,
            default: false
        },
        deleteFlag: {
            type: Boolean,
            default: false
        },
        editTableRow: {
            type: Object,
            defautl: () => {
                return {}
            }
        }
    },
    watch: {
    },
    data() {
        return {
            saveLoading:false,
            pageData: {},
            form:{
                deviceCodes:[],
                isDelPersion:"0"
            },
            devOptions: []

        }
    },
    mounted() {
        console.log(this.editTableRow);
        this.deviceinfoGetallonlinedevices()
    },
    methods: {
        save(){
            var result=[]
            if(this.form.deviceCodes.length){
                result=JSON.parse(JSON.stringify(this.form.deviceCodes))
            }else{
                result=[]
            }
          this.handleCloseDialog()
            try {
                var delPersion=this.form.isDelPersion=="0"?false:true
                console.log('父组件1',this.$parent.applyToDeviceFn(this.form.deviceCodes,delPersion));
            }catch (e) {
                console.log('父组件2',this.$parent.$parent.applyToDeviceFn(this.form.deviceCodes));
            }

            // console.log('父组件1',this.$parent.applyToDeviceFn(this.form.deviceCodes));
            // console.log('父组件2',this.$parent.$parent.applyToDeviceFn(this.form.deviceCodes));

            // this.$parent.$parent.applyToDeviceFn(this.form.deviceCodes)



        },


        // 获取在线设备列表
        deviceinfoGetallonlinedevices() {
            deviceinfoGetallonlinedevices(this.form).then((res) => {
                if (res.code == 200) {
                    this.devOptions = res.data
                    // this.devOptions=[
                    //     {
                    //         deviceCode:'111111',
                    //         deviceName:'前台设备'
                    //     },
                    //     {
                    //         deviceCode:'22222',
                    //         deviceName:'会议室'
                    //     },
                    //     {
                    //         deviceCode:'33333',
                    //         deviceName:'过道'
                    //     },
                    //     {
                    //         deviceCode:'44444',
                    //         deviceName:'外卖'
                    //     }
                    // ]
                }
            }).catch().finally(() => {
            })
        },
        /**
         * @description  关闭弹窗事件
         * @return not
         * @author xiongyi 2022-11-18 16:48:08
         **/
        handleCloseDialog() {
            this.$emit('update:deleteFlag', false);
            this.$emit('update:editTableRow', null);


            try {
                this.$parent.resetLoading()
            }catch (e) {
                this.$parent.$parent.resetLoading()
            }

            // try {
            //     console.log('父组件1');
            //     this.$parent.getdepartmenttree()
            //     this.$parent.onSearch()
            // }catch (e) {
            //     console.log('父组件2');
            //     this.$parent.$parent.getdepartmenttree()
            //     this.$parent.$parent.onSearch()
            // }

        },


    }
}
</script>

<style scoped lang="scss">
.khzhgl-xq-dialog {
    .xqItem {
        display: flex;
        .xql {
            width: 100px;
            text-align: right;
            margin-right: 10px;
            color: rgba(114, 123, 143, 1);
        }
        .xqr {
            flex: 1;
            color: rgba(38, 43, 50, 1);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    }
}
</style>
